package com.tienon.message.thread.task;



import com.tienon.message.entity.Push_App;
import com.tienon.message.util.ErrorMsg;
import com.tienon.message.util.SpringUtil;

public class AppSendMsgTask extends SendMsgTask<Push_App> {

	public AppSendMsgTask(Push_App data) {
		super(data);
	}

	@Override
	protected boolean prepareHandling() {

		log.info("app 消息处理");
		log.info("\n1.定位客户，识别客户渠道标识号\n2.黑白名单处理\n3.屏蔽敏感词 \n4.处理消息前后缀\n");

		return true;
	}

	@Override
	protected boolean splitMsg() {

		log.info("\n消息内容拆分\n");

		return true;
	}

	protected boolean insertDataToMsgAndUpdateRawMsg() throws Exception {
		boolean result = false;
		log.info("\n1.将拆分后的消息写入对应渠道的发送表(可能存在多条）\n2.修改发送原始表状态为发送成功\n");
		try {
			AppSendMsgDBSubTask subTask = SpringUtil
					.getBean(AppSendMsgDBSubTask.class);
			subTask.addPushAppAndUpdateRawMsgBatch(data);
			log.info("批次号："+data.getBatId()+"流水号："+ data.getSerial() +"内容:"+data.getMsg()+"成功插入发送表Push_App");
			result = true;
		} catch (Exception e) {
			result = ErrorMsg.isRepeatInsert(e);
			log.info("批次号："+data.getBatId()+"流水号："+ data.getSerial() +"内容:"+data.getMsg()+"Push_App插入数据有异常，异常原因:"+ErrorMsg.getErrorMsg(e)+result);
			if(!result){
				e.printStackTrace();
			}
			
			
		}
		if(result == true){
			log.info("批次号："+data.getBatId()+"流水号："+ data.getSerial() +"内容:"+data.getMsg()+"成功插入发送表Push_App" + result);
		}else{
			log.info("批次号："+data.getBatId()+"流水号："+ data.getSerial() +"内容:"+data.getMsg()+"插入发送表Push_App失败，具体异常原因在以上堆栈打印"+result);
		}
		return result;

	}

}
